package com.hnx.admin.aurora.core.func;

import com.hnx.admin.aurora.annotation.DeleteInfo;
import com.hnx.admin.aurora.core.SafeDeleteSqlBuilder;
import com.hnx.admin.aurora.core.SqlWithParams;
import com.hnx.admin.aurora.core.api.BuildSqlStrategy;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/*
创建人： 倔强的头发
创建时间：2025/7/3
功能描述:

*/
public class BuildDeleteSql implements BuildSqlStrategy {
    @Override
    public SqlWithParams process(Method method, Object obj) {
        DeleteInfo annotation = method.getAnnotation(DeleteInfo.class);
        if(Objects.nonNull(annotation)){
            Map<String, Object> param = new HashMap<>();
            param.put(ID,obj);
            SafeDeleteSqlBuilder builder = new SafeDeleteSqlBuilder()
                    .delete(TABLE);
            if(obj instanceof java.lang.String){
                builder.where("id=?",param.get(ID));
            }else{
                builder.whereIn(ID, List.of(param.get(ID)));
            }
            return builder.build();
        }
        return null;
    }
}
